<template>
  <section id="how" class="observe">
    <div class="container">
      <h2 data-i18n="sec_how">三步上手 · 生成爆款</h2>
      <p class="subtitle" data-i18n="sec_how_desc">无需剪辑基础</p>
      
      <div class="steps">
        <!-- 步骤 1 -->
        <div class="card">
          <div class="step-num">1</div>
          <h3 data-i18n="how1_t">🎯 选择模板或导入脚本</h3>
          <p data-i18n="how1_d">从营销、测评、资讯、口播等分类中挑选或粘贴文字脚本。</p>
          <div class="step-img">
            <div class="tpl">
              <div class="tpl-header">
                <div class="tpl-title">热门模板</div>
                <div class="tpl-filter">全部分类 ▾</div>
              </div>
              <div class="tpl-grid">
                <div class="tpl-item">
                  <div class="tpl-thumb cover--1"></div>
                  <div class="tpl-name">产品测评</div>
                </div>
                <div class="tpl-item">
                  <div class="tpl-thumb cover--2"></div>
                  <div class="tpl-name">热点解读</div>
                </div>
                <div class="tpl-item active">
                  <div class="tpl-thumb cover--3"></div>
                  <div class="tpl-name">品牌故事</div>
                </div>
                <div class="tpl-item">
                  <div class="tpl-thumb cover--4"></div>
                  <div class="tpl-name">教程讲解</div>
                </div>
              </div>
              <div class="tpl-import">
                <div class="tpl-import-icon">📄</div>
                <div class="tpl-import-text">导入脚本</div>
              </div>
            </div>
          </div>
        </div>
        
        <!-- 步骤 2 -->
        <div class="card">
          <div class="step-num">2</div>
          <h3 data-i18n="how2_t">⚡ 一键智能排版</h3>
          <p data-i18n="how2_d">自动镜头切分、素材匹配、字幕与配音生成，可手动微调。</p>
          <div class="step-img">
            <div class="editor">
              <div class="editor-sidebar">
                <div class="sidebar-item active">素材</div>
                <div class="sidebar-item">文本</div>
                <div class="sidebar-item">特效</div>
                <div class="sidebar-item">音频</div>
              </div>
              <div class="editor-main">
                <div class="editor-preview">
                  <div class="preview-screen"></div>
                  <div class="preview-controls">
                    <div class="control">⏪</div>
                    <div class="control play">▶</div>
                    <div class="control">⏩</div>
                  </div>
                </div>
                <div class="editor-timeline">
                  <div class="timeline-track video">
                    <div class="track-clip"></div>
                    <div class="track-clip active"></div>
                    <div class="track-clip"></div>
                  </div>
                  <div class="timeline-track audio">
                    <div class="track-clip"></div>
                  </div>
                  <div class="timeline-track text">
                    <div class="track-clip"></div>
                    <div class="track-clip"></div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        
        <!-- 步骤 3 -->
        <div class="card">
          <div class="step-num">3</div>
          <h3 data-i18n="how3_t">🚀 云端渲染与发布</h3>
          <p data-i18n="how3_d">多平台比例适配，自动生成封面与话题标签，直接分发。</p>
          <div class="step-img">
            <div class="export">
              <div class="export-options">
                <div class="export-option active">
                  <div class="option-icon">📱</div>
                  <div class="option-text">竖屏 9:16</div>
                </div>
                <div class="export-option">
                  <div class="option-icon">🖥️</div>
                  <div class="option-text">横屏 16:9</div>
                </div>
                <div class="export-option">
                  <div class="option-icon">◼️</div>
                  <div class="option-text">方形 1:1</div>
                </div>
              </div>
              <div class="export-preview">
                <div class="preview-device">
                  <div class="device-screen">
                    <div class="device-content"></div>
                    <div class="device-progress">
                      <div class="progress-bar"></div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="export-platforms">
                <div class="platform-icon">📱</div>
                <div class="platform-icon">🎬</div>
                <div class="platform-icon">🔴</div>
                <div class="platform-icon">📺</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>

<script setup>
import { onMounted } from 'vue';

// 国际化字典
const i18n = {
  zh: {
    sec_how: '三步上手 · 生成爆款',
    sec_how_desc: '无需剪辑基础',
    how1_t: '🎯 选择模板或导入脚本',
    how1_d: '从营销、测评、资讯、口播等分类中挑选或粘贴文字脚本。',
    how2_t: '⚡ 一键智能排版',
    how2_d: '自动镜头切分、素材匹配、字幕与配音生成，可手动微调。',
    how3_t: '🚀 云端渲染与发布',
    how3_d: '多平台比例适配，自动生成封面与话题标签，直接分发。'
  },
  en: {
    sec_how: '3 steps to viral',
    sec_how_desc: 'No editing skills required',
    how1_t: '🎯 Pick a template or paste script',
    how1_d: 'Choose from marketing/review/news/talking categories.',
    how2_t: '⚡ Auto layout',
    how2_d: 'Auto shots, assets, subtitles & VO with manual tweaks.',
    how3_t: '🚀 Render & publish',
    how3_d: 'Multi-ratio exports, auto cover & tags, one-click publish.'
  },
  es: {
    sec_how: '3 pasos al éxito',
    sec_how_desc: 'Sin experiencia en edición',
    how1_t: '🎯 Elige plantilla o pega guion',
    how1_d: 'Marketing/reseñas/noticias/habla.',
    how2_t: '⚡ Maquetación automática',
    how2_d: 'Planos, assets, subtítulos y voz automáticos.',
    how3_t: '🚀 Render y publicación',
    how3_d: 'Múltiples formatos, portada y etiquetas automáticas.'
  }
};

// 应用语言
const applyLang = (lang) => {
  const dict = i18n[lang];
  if (!dict) return;
  
  document.querySelectorAll('[data-i18n]').forEach(el => {
    const key = el.dataset.i18n;
    if (dict[key]) el.innerHTML = dict[key];
  });
};

// 生命周期钩子
onMounted(() => {
  // 初始化语言
  const savedLang = localStorage.getItem('lang') || 'zh';
  applyLang(savedLang);
  
  // 监听语言变化
  window.addEventListener('storage', (e) => {
    if (e.key === 'lang') {
      applyLang(e.newValue);
    }
  });
  
  // 设置观察器，当元素进入视口时添加reveal类
  const observer = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        entry.target.classList.add('reveal');
      }
    });
  }, { threshold: 0.12 });
  
  document.querySelectorAll('.observe .card').forEach(el => {
    observer.observe(el);
  });
  
  // 模拟进度条动画
  const progressBar = document.querySelector('.progress-bar');
  if (progressBar) {
    setInterval(() => {
      const currentWidth = parseInt(progressBar.style.width || '0');
      if (currentWidth >= 100) {
        progressBar.style.width = '0%';
      } else {
        progressBar.style.width = (currentWidth + 1) + '%';
      }
    }, 50);
  }
});
</script>

<style scoped>
/* 三步上手区域样式 */
#how {
  padding: 80px 0;
}

h2 {
  text-align: center;
  font-size: 36px;
  margin-bottom: 16px;
}

.subtitle {
  text-align: center;
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 60px;
}

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30px;
}

.card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  position: relative;
  transition: all 0.4s ease;
  opacity: 0;
  transform: translateY(20px);
}

.card.reveal {
  opacity: 1;
  transform: translateY(0);
}

.card:nth-child(2) {
  transition-delay: 0.2s;
}

.card:nth-child(3) {
  transition-delay: 0.4s;
}

.step-num {
  position: absolute;
  top: -15px;
  left: 24px;
  width: 30px;
  height: 30px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
}

h3 {
  font-size: 20px;
  margin-bottom: 12px;
  margin-top: 10px;
}

p {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.step-img {
  height: 240px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--shot-bg);
}

/* 模板选择界面样式 */
.tpl {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px;
}

.tpl-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.tpl-title {
  font-weight: 600;
  font-size: 16px;
}

.tpl-filter {
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
}

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.tpl-item {
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
}

.tpl-item:hover {
  transform: translateY(-3px);
}

.tpl-item.active {
  border-color: var(--primary);
}

.tpl-thumb {
  height: 100px;
  background: var(--thumb-bg);
  border-radius: 6px 6px 0 0;
}

.tpl-name {
  padding: 8px;
  font-size: 12px;
  text-align: center;
  background: var(--card-bg);
}

.tpl-import {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: auto;
}

.tpl-import:hover {
  background: var(--hover);
  border-color: var(--primary);
}

.tpl-import-icon {
  font-size: 20px;
}

.tpl-import-text {
  font-size: 14px;
}

/* 编辑器界面样式 */
.editor {
  height: 100%;
  display: flex;
}

.editor-sidebar {
  width: 60px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 12px;
}

.sidebar-item {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-item:hover {
  background: var(--hover);
}

.sidebar-item.active {
  background: var(--primary);
  color: white;
}

.editor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.editor-preview {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.preview-screen {
  flex: 1;
  background: #000;
  border-radius: 8px;
  margin-bottom: 12px;
}

.preview-controls {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.control {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--control-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.control:hover {
  background: var(--hover);
}

.control.play {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: white;
}

.editor-timeline {
  height: 80px;
  background: var(--timeline-bg);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.timeline-track {
  height: 20px;
  background: var(--track-bg);
  border-radius: 4px;
  display: flex;
  gap: 2px;
  padding: 2px;
}

.timeline-track.video {
  background: rgba(0, 102, 255, 0.1);
}

.timeline-track.audio {
  background: rgba(255, 102, 0, 0.1);
}

.timeline-track.text {
  background: rgba(0, 204, 102, 0.1);
}

.track-clip {
  height: 16px;
  background: var(--clip-bg);
  border-radius: 3px;
  flex: 1;
}

.timeline-track.video .track-clip {
  background: rgba(0, 102, 255, 0.3);
}

.timeline-track.video .track-clip.active {
  background: rgba(0, 102, 255, 0.7);
}

.timeline-track.audio .track-clip {
  background: rgba(255, 102, 0, 0.3);
}

.timeline-track.text .track-clip {
  background: rgba(0, 204, 102, 0.3);
}

/* 导出界面样式 */
.export {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px;
}

.export-options {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.export-option {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.export-option:hover {
  background: var(--hover);
}

.export-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-icon {
  font-size: 20px;
}

.option-text {
  font-size: 12px;
}

.export-preview {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
}

.preview-device {
  width: 120px;
  height: 220px;
  background: #111;
  border-radius: 16px;
  padding: 8px;
  position: relative;
}

.device-screen {
  width: 100%;
  height: 100%;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.device-content {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1423 0%, #372549 45%, #774c60 100%);
}

.device-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.2);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.1s linear;
}

.export-platforms {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.platform-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--platform-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.platform-icon:hover {
  transform: translateY(-3px);
  background: var(--hover);
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .steps {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .card:nth-child(3) {
    grid-column: 1 / -1;
    max-width: 500px;
    margin: 0 auto;
  }
}

@media (max-width: 768px) {
  .steps {
    grid-template-columns: 1fr;
  }
  
  .card {
    max-width: 500px;
    margin: 0 auto;
  }
  
  .card:nth-child(3) {
    grid-column: auto;
  }
  
  h2 {
    font-size: 30px;
  }
  
  .subtitle {
    font-size: 16px;
    margin-bottom: 40px;
  }
}

/* 封面样式 */
.cover--1 {
  background-image: linear-gradient(135deg, #10131a 0%, #2a2a72 45%, #009ffd 100%);
  background-blend-mode: overlay;
  background-size: cover;
  background-position: center;
}

.cover--2 {
  background-image: linear-gradient(135deg, #1a1423 0%, #372549 45%, #774c60 100%);
  background-blend-mode: overlay;
  background-size: cover;
  background-position: center;
}

.cover--3 {
  background-image: linear-gradient(135deg, #051937 0%, #004d7a 45%, #008793 100%);
  background-blend-mode: overlay;
  background-size: cover;
  background-position: center;
}

.cover--4 {
  background-image: linear-gradient(135deg, #241e92 0%, #5432d3 45%, #7b6cf6 100%);
  background-blend-mode: overlay;
  background-size: cover;
  background-position: center;
}
</style>